﻿using System;
using System.Collections.Generic;
using System.Web;

using CE.Company;
using CE.Mail;
/// <summary>
/// Summary description for Welcome
/// </summary>

namespace CE.Email
{
    public class Welcome
    {
        //private string _emailTo;
        //private string _emailCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_CC"].ToString();
        //private string _emailBCC = System.Configuration.ConfigurationSettings.AppSettings["TH.CXWelcome_BCC"].ToString();

        public Welcome()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static bool SendMail(string EmailAddress, string UserName, string AuthCode)
        {
            bool _retVal = false;
            try
            {
                //string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
                string _emailTo = EmailAddress;
                Uri myUri = new Uri(HttpContext.Current.Request.Url.ToString());
                string domainUrl = "";
                string redirectUrl = Resources.WelcomeEmail.GG;
                domainUrl = "http://www.gluaygluay.com/mobile";
                string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.IsCXLive");
                if (_strCXLive == "0")
                {
                    domainUrl = "http://test.gluaygluay.com.gluaygluay.info/mobile";
                    redirectUrl = Resources.WelcomeEmail.GGTest;
                }

                string imgLogoUrl = domainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("Mobile.TH.LogoPath");
                string _customername = UserName;                
                string _emailSubject = Resources.WelcomeEmail.Subject;  

                CompanyInformation _company = new CompanyInformation();
                CompanyInformationDB _companydb = new CompanyInformationDB();
                _company = _companydb.GetCompanyInformation(2);
                string _companyAddress = "";
                string _emailaddress = "";
                string _websiteaddress = "";
                if (_company != null)
                {
                    _companyAddress = _company.Address1;
                    _emailaddress = _company.EmailAddress;
                    _websiteaddress = _company.Website;
                }
                _company = null;
                _companydb = null;

                string _mailBody = "";

                string _strEncryptedEmail = "";
                string key = "cxDAtravel";
                CXDecryption.Decryption cxd = new CXDecryption.Decryption();
                if (EmailAddress.ToString() != "" && EmailAddress.ToString() != null)
                {
                    byte[] UesrEmail = cxd.Encrypt(EmailAddress, key);
                    _strEncryptedEmail = Convert.ToBase64String(UesrEmail);
                }

                #region "New - Mailbody"
                _mailBody = "<html>";
                _mailBody += "<head>";
                _mailBody += "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />";
                _mailBody += "<title>GluayGluay</title>";
                _mailBody += "<style>";

                _mailBody += ".body {";
                _mailBody += "margin-left: 0px;";
                _mailBody += "margin-top: 0px;";
                _mailBody += "margin-right: 0px;";
                _mailBody += "margin-bottom: 0px;";
                _mailBody += "font-family: Arial, sans-serif;";
                _mailBody += "font-size: 14px;";
                _mailBody += "color: black;";
                _mailBody += "background-repeat: repeat-x;";
                _mailBody += "background-color: #fff;";
                _mailBody += "text-decoration: none;}";

                _mailBody += "hr {";
                _mailBody += "display: block;";
                _mailBody += "height: 1px;";
                _mailBody += "border: 0;";
                _mailBody += "border-top: 1px solid #ccc;";
                _mailBody += "margin: 1em 0;";
                _mailBody += "padding: 0;}";

                _mailBody += "</style>";
                _mailBody += "</head>";

                _mailBody += "<body class='body'>";
                _mailBody += "<table width='800' border='0' align='center' cellpadding='0' cellspacing='0'>";
                _mailBody += "<tr>";
                _mailBody += "<td height='653' align='right' valign='bottom'><table width='800' height='100' border='0' cellspacing='0' cellpadding='0'>";
                _mailBody += "<tr>";
                _mailBody += "<td><span class='email-banner'>";
                _mailBody += "<a href='" + redirectUrl + "' target='_blank'>";
                _mailBody += "<img src='" + domainUrl + Resources.EmailMessage.EmailBannerUrl + "' width='800' height='182' alt='' /></a>";
                _mailBody += "</span></td>";
                _mailBody += "</tr>";
                _mailBody += "</table>";
                _mailBody += "<table width='800' border='0' align='center' cellspacing='0' cellpadding='0'>";
                _mailBody += "<tr>";
                _mailBody += "<td width='530' valign='top'><p><strong>" + Resources.WelcomeEmail.Hi + " " + _customername + "</strong>,</p>";
                _mailBody += "<p style='text-align: justify'>";
                _mailBody += Resources.WelcomeEmail.WecomeBody;
                _mailBody += "</p>";
                _mailBody += "<p><strong>" + Resources.WelcomeEmail.WecometoHelp + "</strong></p>";
                _mailBody += "<p>" + Resources.WelcomeEmail.WecometoHelpBody + "</p>";
                _mailBody += "<p>";
                _mailBody += Resources.WelcomeEmail.Sincerely + "</p>";
                _mailBody += "<p>";
                _mailBody += Resources.WelcomeEmail.GGCustomerServiceTeam + "<br />";
                _mailBody += "<strong>" + Resources.WelcomeEmail.CompanyAdd1 + "</strong><br />";
                _mailBody += Resources.WelcomeEmail.CompanyAdd2 + "<br />";
                _mailBody += Resources.WelcomeEmail.CompanyAdd3 + "<br />";
                _mailBody += Resources.WelcomeEmail.CompanyAdd4 + "<br />";
                _mailBody += "<br />";
                _mailBody += "</p>";
                _mailBody += "<p>";
                _mailBody += Resources.WelcomeEmail.WelcomePromiseStart + EmailAddress + ". " + Resources.WelcomeEmail.WelcomePromise;
                _mailBody += "<a href='" + domainUrl + Resources.WelcomeEmail.UnsubscribeUrl + "?uid=" + _strEncryptedEmail + "' target='_blank'>" + Resources.WelcomeEmail.ImportantUpdates + "</a>.<br />";
                _mailBody += "</p>";
                _mailBody += "</p></td><td width='270' valign='middle'><img src='" + domainUrl + "/images/email-chac.jpg' width='270' height='181' alt=''/></td>";
                _mailBody += "</tr>";
                _mailBody += "</table>";
                _mailBody += "<br />";
                _mailBody += "<hr />";
                _mailBody += "<br />";

                _mailBody += "<table width='300' border='0' align='center' cellpadding='0' cellspacing='0'>";
                _mailBody += "<tr>";
                _mailBody += "<td width='44' style='text-align: center'>";
                _mailBody += "<a href='https://www.facebook.com/GGmotor' target='_blank'><img src='" + domainUrl + "/images/icons/fb-big.png' width='44' height='42'></a>";
                _mailBody += "</td>";
                _mailBody += "<td width='44' style='text-align: center'>";
                _mailBody += "<a href='https://plus.google.com/+Gluaygluay/posts' target='_blank'><img src='" + domainUrl + "/images/icons/g-plus-big.png' width='44' height='42'></a>";
                _mailBody += "</td>";
                _mailBody += "<td width='44' style='text-align: center'>";
                _mailBody += "<a href='http://www.youtube.com/channel/UCZ4gMtlXymBHxvcXO2cR1vA' target='_blank'><img src='" + domainUrl + "/images/icons/youtube-big.png' width='44' height='42'></a>";
                _mailBody += "</td>";
                _mailBody += "<td width='44' style='text-align: center'>";
                _mailBody += "<a href='http://iconosquare.com/ggmotor' target='_blank'><img src='" + domainUrl + "/images/icons/instagram-big.png' width='44' height='42'></a>";
                _mailBody += "</td>";
                _mailBody += "<td width='43' style='text-align: center'>";
                _mailBody += "<a href='http://www.linkedin.com/company/-com-gluaygluay-com-' target='_blank'><img src='" + domainUrl + "/images/icons/linkedin-big.png' width='44' height='42'></a>";
                _mailBody += "</td>";
                _mailBody += "</tr>";
                _mailBody += "</table>";

                _mailBody += "<table width='800' height='100' border='0' cellspacing='0' cellpadding='0' background='" + domainUrl + "/images/email-footer.jpg'>";
                _mailBody += "<tr>";
                _mailBody += "<td height='49'><p style='text-align: center'>© 2015 gluaygluay.com. All rights reserved.<br>";
                _mailBody += Resources.EmailMessage.AutoEmail + "</p></td>";
                _mailBody += "</tr>";
                _mailBody += "</table></td>";
                _mailBody += "</tr>";
                _mailBody += "</table>";
                _mailBody += "</body>";
                _mailBody += "</html>";
                #endregion

                if (MyMailManager.SendWelcomeMessage(_emailTo, _emailSubject, _mailBody))
                {
                    _retVal = true;
                }
                else
                {
                    _retVal = false;
                }
            }
            catch (Exception Ex)
            {
                _retVal = false;               
                
            }

            return _retVal;
        }
    }
}
